﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.DomainModel;
using Enterprise.Framework.DomainModel.Repositories;
using Resto.CostControl.Common.Utility;

namespace Resto.CostControl.Core.Domain.Model
{
    /// <summary>
    /// 项目点的每周订单
    /// </summary>
    public partial class WeekDishOrder : IAggregationRoot
    {
        #region 构造函数

        internal WeekDishOrder()
        {
            this.ID = IDHelper.CreateNewID();
        }

        #endregion

        #region 私有属性

        private IEntityRepository<WeekDishOrder> _Repository;
        private IEntityRepository<WeekDishOrder> Repository
        {
            get
            {
                if (_Repository == null)
                    _Repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<WeekDishOrder>();

                return _Repository;
            }
        }

        #endregion

        #region 业务方法

        internal void Add()
        {
            this.CreateAudit = new Audit();
            this.LastUpdateAudit = new Audit();

            this.Repository.Add(this);
        }

        internal void Update()
        {
            foreach (DishOrder order in this.DishOrders)
                order.LastUpdateAudit = new Audit();

            this.Repository.Update(this);
        }

        internal void Delete()
        {
            this.Repository.Delete(this);
        }

        internal void AddOrder(DishOrder order)
        {
            this.DishOrders.Add(order);
        }

        internal DishOrder GetOrder(string orderId)
        {
            return this.DishOrders.Where(p => p.ID == orderId).FirstOrDefault();
        }
        
        #endregion
    }
}
